<template>
  <div style="margin-top: 12px;">
    <van-uploader v-model="fileList" @click-preview="tapFile" :deletable="false" class="vans" />
  </div>
</template>

<script>
import env from "@/assets/js/env";
export default {
  data() {
    return {
      fileList: []
    };
  },
  props: {
    pfileList: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  mounted() {
    if (this.pfileList.length !== 0) {
      this.pfileList.forEach(item => {
        this.fileList.push({
          externalLink: item.externalLink,
          url: item.externalLink,
          fileName: item.fileName,
          fileType: item.fileType,
          originalFileName: item.originalFileName,
          file: {
            name: item.originalFileName
          }
        });
      });
    }
  },
  watch: {
    pfileList: function(val) {
      if (val.length !== 0) {
        val.forEach(item => {
          this.fileList.push({
            externalLink: item.externalLink,
            url: item.externalLink,
            fileName: item.fileName,
            fileType: item.fileType,
            originalFileName: item.originalFileName,
            file: {
              name: item.originalFileName
            }
          });
        });
      }
    }
  },
  methods: {
    tapFile(file) {
      if (
        file.fileType == "jpg" ||
        file.fileType == "png" ||
        file.fileType == "img"
      ) {
      } else {
		  console.log(env+"/api/oss/downloadOSS?fileName=" +encodeURIComponent(file.fileName))
        window.bridge.onFileDownload(
          JSON.stringify({
            source: "Result_statistic",
            fileType: file.fileType,
            url: env+"/api/oss/downloadOSS?fileName=" +encodeURIComponent(file.fileName)
          })
        );
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.vans {
  ::v-deep .van-uploader__upload {
    display: none;
  }
}
</style>
